package com.example.day3.exercise;

import java.util.Comparator;
import java.util.List;

/**
 * 三级排序
 */
public class Exercise3 {
    public static void main(String[] args) {
        List<Student> students = List.of(
                new Student("张三", 85, 20, "北京"),
                new Student("李四", 92, 19, "上海"),
                new Student("王五", 85, 21, "北京"),
                new Student("赵六", 92, 19, "广州"),
                new Student("钱七", 78, 22, "深圳"),
                new Student("孙八", 85, 20, "杭州")
        );

        System.out.println("\n三级排序后 (按分数降序 -> 年龄升序 -> 姓名升序):");
        students.stream()
                .sorted(Comparator.comparingInt(Student::score).reversed()
                        .thenComparing(Student::age)
                        .thenComparing(Student::name))
                .forEach(System.out::println);
    }

    record Student(String name, int score, int age, String city) {
    }
}
